package com.lhkj.ct.meta.modules.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.lhkj.ct.meta.modules.auth.common.enums.IdentType;
import com.lhkj.ct.meta.modules.auth.common.enums.UserType;
import com.lhkj.ct.meta.modules.auth.entity.TblUserIdentity;
import com.lhkj.ct.meta.modules.auth.mapper.UserIdentityMapper;
import com.lhkj.ct.meta.modules.auth.service.UserIdentityService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 第三方授权表 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2023-11-13
 */
@Service
public class UserIdentityServiceImpl extends ServiceImpl<UserIdentityMapper, TblUserIdentity> implements UserIdentityService {

    @Override
    public boolean unbind(UserType userType, IdentType identType, String identity) {
        LambdaQueryWrapper<TblUserIdentity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TblUserIdentity::getUserType, userType)
                .eq(TblUserIdentity::getIdentType, identType)
                .eq(TblUserIdentity::getIdentifier, identity);
        return SqlHelper.retBool(getBaseMapper().delete(queryWrapper));
    }

    @Override
    public TblUserIdentity getByIdentity(UserType userType, IdentType identType, String identity) {
        return getBaseMapper().selectOne(new LambdaQueryWrapper<TblUserIdentity>()
                .eq(TblUserIdentity::getUserType, userType)
                .eq(TblUserIdentity::getIdentType, identType)
                .eq(TblUserIdentity::getIdentifier, identity)
        );
    }
}
